'''Class for special handling of DocBook document types.
It sets lang attribute on article elements, and adds translators
to articleinfo/copyright.'''
def __init__(self):
self.lists = [
'itemizedlist',
'orderedlist',
'variablelist',
'segmentedlist',
'simplelist',
'calloutlist',
'varlistentry']
self.objects = [
'figure',
'textobject',
'imageobject',
'mediaobject',
'screenshot']
def getIgnoredTags(self):
'''Returns array of tags to be ignored.'''
return self.objects + self.lists
def getFinalTags(self):
"""Returns array of tags to be considered 'final'."""
return [
'para',
'formalpara',
'simpara',
'releaseinfo',
'revnumber',
'title',
'date',
'term',
'programlisting'] + self.objects + self.lists
def getSpacePreserveTags(self):
'''Returns array of tags in which spaces are to be preserved.'''
return [
'classsynopsisinfo',
'computeroutput',
'funcsynopsisinfo',
'literallayout',
'programlisting',
'screen',
'synopsis',
'userinput']
def getTreatedAttributes(self):
'''Returns array of tag attributes which content is to be translated'''
return []
def getStringForTranslators(self):
'''Returns string which will be used to credit translators.'''
return 'translator-credits'
def getCommentForTranslators(self):
'''Returns a comment to be added next to string for crediting translators.'''
return 'Put one translator per line, in the form of NAME <EMAIL>, YEAR1, YEAR2.'
def _find_articleinfo(self, node):
if node.name == 'articleinfo' or node.name == 'bookinfo':
return node
child = node.children
while child:
ret = self._find_articleinfo(child)
if ret:
return ret
child = child.next
def _find_lastcopyright(self, node):
if not node.children:
return None
last = node.lastChild()
tmp = last
while tmp:
if tmp.name == 'copyright':
last = tmp
break
tmp = tmp.prev
return last
def _md5_for_file(self, filename):
hash = md5.new()
input = open(filename, 'rb')
read = input.read(4096)
while read:
hash.update(read)
read = input.read(4096)
input.close()
return hash.hexdigest()
def _output_images(self, node, msg):
if node and node.type == 'element' and node.name == 'imagedata':
attr = node.prop('fileref')
if attr:
dir = os.path.dirname(msg.filename)
fullpath = os.path.join(dir, attr)
if os.path.exists(fullpath):
hash = self._md5_for_file(fullpath)
else:
hash = "THIS FILE DOESN'T EXIST"
print >>sys.stderr, "Warning: image file '%s' not found." % fullpath
msg.outputMessage("@@image: '%s'; md5=%s" % (attr, hash), node.lineNo(), 'When image changes, this message will be marked fuzzy or untranslated for you.\n' + "It doesn't matter what you translate it to: it's not used at all.")